﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

using Ccit.Global;
using Ccit.OA.Utils;
using System.Data.SqlClient;
using Ccit.Utils;

namespace Ccit.OA.NewsCenter
{
    public class WindowSQL:IWindow
    {
        #region
        /// <summary>
        /// 获取本人的窗口列表信息
        /// </summary>
        /// <returns></returns>
        public List<MsWinStyle> GetWindowList(string winName,string Type)
        {
            string sType = (Type != "") ? Type : "0";

           // string plateIds = getUserIds();  // 获取当前用户的板块ids,其中NEWS_A8_70窗口标志为1
            
            List<MsWinStyle> windowList = new List<MsWinStyle>();
            
            LoginUser login = (LoginUser)HttpContext.Current.Session["LogUserInfo"];

            string cmdText = " SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM NEWS_B2 WHERE 1=1 AND NEWS_B2_120 = '" + sType + "' AND NEWS_B2_130 = '" + login.UserId + "' AND NEWS_B2_10 > 0";
            
            if(winName!=""){
                cmdText += " AND NEWS_B2_20 LIKE '%"+winName.Replace("'","''")+"%'";
            }
    
            using(IDataReader ireader=DataAccessor.ExecuteReader(cmdText))
            {
                while(ireader.Read()){
                    MsWinStyle mw = new MsWinStyle();
                    mw.PlateId = ireader["NEWS_B2_10"].ToString();
                    mw.PlateName = ireader["NEWS_B2_20"].ToString();
                    mw.ShowNum = ireader["NEWS_B2_80"].ToString();
                    mw.ShowCreateor = ireader["NEWS_B2_90"].ToString();
                    mw.ShowPubTime = ireader["NEWS_B2_100"].ToString();
                    windowList.Add(mw);
                }
            }
            return windowList;
        }
        ///// <summary>
        ///// 获取当前用户所有的板块
        ///// </summary>
        ///// <param name="Type"></param>
        ///// <returns></returns>
        //public List<MsWinStyle> GetAllPlate(string Type)
        //{
        //    LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];

        //    string sType = (Type != "") ? Type : "0";

        //    //窗口设置
        //    List<MsWinStyle> windowList = new List<MsWinStyle>();
        //    //获取系统板块
        //    string sysPlate = "SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM NEWS_B2 WHERE NEWS_B2_10 < 0 AND NEWS_B2_130 = '"+loginUser.UserId+"'";

        //    using (IDataReader ireader = DataAccessor.ExecuteReader(sysPlate))
        //    {
        //        while (ireader.Read())
        //        {
        //            MsWinStyle mw = new MsWinStyle();
        //            mw.PlateId = ireader["NEWS_B2_10"].ToString();
        //            mw.PlateName = ireader["NEWS_B2_20"].ToString();
        //            mw.ShowNum = ireader["NEWS_B2_80"].ToString();
        //            mw.ShowCreateor = ireader["NEWS_B2_90"].ToString();
        //            mw.ShowPubTime = ireader["NEWS_B2_100"].ToString();
        //            windowList.Add(mw);
        //        }
        //    }

        //    string plateIds = getUserIds();  // 获取当前用户的板块ids,其中NEWS_A8_70窗口标志为1

        //    string cmdText = " SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM NEWS_B2 WHERE 1=1 AND NEWS_B2_120 = '" + sType + "' ";

        //    if (plateIds.Length > 0)
        //    {
        //        plateIds = plateIds.Substring(0, plateIds.Length - 1);
        //        cmdText += " AND NEWS_B2_10 IN (" + plateIds + ")";
        //    }
        //    else
        //    {
        //        return windowList;
        //    }

        //    using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
        //    {
        //        while (ireader.Read())
        //        {
        //            MsWinStyle mw = new MsWinStyle();
        //            mw.PlateId = ireader["NEWS_B2_10"].ToString();
        //            mw.PlateName = ireader["NEWS_B2_20"].ToString();
        //            mw.ShowNum = ireader["NEWS_B2_80"].ToString();
        //            mw.ShowCreateor = ireader["NEWS_B2_90"].ToString();
        //            mw.ShowPubTime = ireader["NEWS_B2_100"].ToString();
        //            windowList.Add(mw);
        //        }
        //    }
        //    return windowList;
        //}
        
        /// <summary>
        /// 删除操作
        /// </summary>
        /// <param name="plateId">板块ID</param>
        /// <returns></returns>
        public List<string> RemoveWinStyle(string plateId,string Type)
        {
            string sType = (Type != "") ? Type : "0";
            LoginUser login = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            List<string> slist=new List<string>();
            if (plateId == "")
            {
                slist.Add("-999");
                slist.Add("删除失败,缺少必要的参数");
                return slist;
            }
            string cmdText = " DELETE FROM  NEWS_B2 WHERE NEWS_B2_10='" + plateId + "' AND NEWS_B2_120 = '" + sType + "'  AND NEWS_B2_130 = '"+login.UserId+"'  ";
            if (0 < DataAccessor.ExecuteNonQuery(cmdText))
            {
                slist.Add("1");
                slist.Add("删除成功");
            }
            else
            {
                slist.Add("-1");
                slist.Add("删除失败,系统忙,请稍后再试");
            }
            return slist;
        }
        /// <summary>
        /// 获取单个对象
        /// </summary>
        /// <param name="plateId">NEWS_B2_10</param>
        /// <returns></returns>
        public MsWinStyle GetWinStyleObj(string plateId,string Type)
        {
            MsWinStyle winObj = null;
            if (plateId == "") return winObj;
            string sType = (Type != "")  ? Type : "0";
            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            string cmdText = "SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_60,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM NEWS_B2 WHERE NEWS_B2_10='" + plateId + "'  AND NEWS_B2_120 = '" + sType + "' AND NEWS_B2_130='" + loginUser.UserId + "'";
            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            {
                while(ireader.Read()){
                    winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
                    winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
                    winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
                    winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
                }
            }
            return winObj;
        }

        /// <summary>
        /// 获取系统板块的属性对象
        /// </summary>
        /// <param name="plateId"></param>
        /// <param name="Type"></param>
        /// <param name="vUserId"></param>
        /// <returns></returns>
        public MsWinStyle GetWinDefault(string plateId, string Type, string vUserId)
        {
            MsWinStyle winObj = null;
            if (plateId == "") return winObj;
            string sType = (Type != "") ? Type : "0";
            string cmdText = "SELECT * FROM NEWS_B2 WHERE NEWS_B2_10='" + plateId + "'  AND NEWS_B2_120 = '" + sType + "' AND NEWS_B2_130='"+vUserId+"'";
            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            {
                while (ireader.Read())
                {
                    winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winObj.ShowArea = ireader["NEWS_B2_40"].ToString();
                    winObj.OrderNo = ireader["NEWS_B2_50"].ToString();
                    winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
                    winObj.SysFlag = ireader["NEWS_B2_70"].ToString();
                    winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
                    winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
                    winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
                    winObj.OtherSet = ireader["NEWS_B2_110"].ToString();
                    winObj.PlateType = ireader["NEWS_B2_120"].ToString();
                    winObj.UserId = ireader["NEWS_B2_130"].ToString();
                }
            }
            return winObj;
        }
        /// <summary>
        /// 保存板块信息
        /// </summary>
        /// <param name="winObj"></param>
        /// <returns></returns>
        public List<string> SaveWinStyle(MsWinStyle winObj, MsQueryClause queryClause,string Type)
        {
            List<string> strlist = new List<string>();
            if (winObj == null) return null;
            if(winObj.PlateId==""){ // 新增
                strlist = doSave(winObj, queryClause,Type); ;
            }
            if(winObj.PlateId!=""){  //编辑
                strlist = doEdit(winObj, queryClause);
            }
            return strlist;
        }

        /// <summary>
        /// 获取知道列的板块信息
        /// </summary>
        /// <param name="cellNum"></param>
        /// <returns></returns>
        public List<MsWinStyle> GetWinShowCell(string cellNum,string Type)
        {
            string sType = (Type != "") ? Type : "0";

            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];

            List<MsWinStyle> winList = new List<MsWinStyle>();
            
            if (string.IsNullOrEmpty(cellNum)) return winList;

            string sSql = "SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_40,NEWS_B2_60,NEWS_B2_70,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM  NEWS_B2 WHERE  NEWS_B2_40 = '" + cellNum + "' AND NEWS_B2_130 = '" + loginUser.UserId + "' AND NEWS_B2_120 = '" + sType + "'";
            using (IDataReader ireader = DataAccessor.ExecuteReader(sSql))
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winObj.ShowArea = ireader["NEWS_B2_40"].ToString();
                    winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
                    winObj.SysFlag = ireader["NEWS_B2_70"].ToString();
                    winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
                    winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
                    winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
                    winList.Add(winObj);
                }
            }

            ////取系统板块
            //string sysPlate = "SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_40,NEWS_B2_60,NEWS_B2_70,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM  NEWS_B2 WHERE NEWS_B2_10 < 0 AND NEWS_B2_40 = '" + cellNum + "' AND NEWS_B2_130 = '" + loginUser.UserId + "' AND NEWS_B2_120 = '" + sType + "'";

            //using (IDataReader ireader = DataAccessor.ExecuteReader(sysPlate))
            //{
            //    while (ireader.Read())
            //    {
            //        MsWinStyle winObj = new MsWinStyle();
            //        winObj.PlateId = ireader["NEWS_B2_10"].ToString();
            //        winObj.PlateName = ireader["NEWS_B2_20"].ToString();
            //        winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
            //        winObj.ShowArea = ireader["NEWS_B2_40"].ToString();
            //        winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
            //        winObj.SysFlag = ireader["NEWS_B2_70"].ToString();
            //        winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
            //        winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
            //        winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
            //        winList.Add(winObj);
            //    }
            //}

            ////取当前用户的板块
            //string cmdText = " SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_40,NEWS_B2_60,NEWS_B2_70,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM  NEWS_B2 WHERE NEWS_B2_40='" + cellNum + "' AND NEWS_B2_120 = '" + sType + "' ";

            //string plateIds = getUserIds();  // 获取当前用户的板块ids,其中NEWS_A8_70窗口标志为1

            //if (plateIds.Length > 0)
            //{
            //    plateIds = plateIds.Substring(0, plateIds.Length - 1);
            //    cmdText += " AND NEWS_B2_10 IN (" + plateIds + ")";
            //}
            //else
            //{
            //    return winList;
            //}

            //    using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            //    {
            //        while (ireader.Read())
            //        {
            //            MsWinStyle winObj = new MsWinStyle();
            //            winObj.PlateId = ireader["NEWS_B2_10"].ToString();
            //            winObj.PlateName = ireader["NEWS_B2_20"].ToString();
            //            winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
            //            winObj.ShowArea = ireader["NEWS_B2_40"].ToString();
            //            winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
            //            winObj.SysFlag = ireader["NEWS_B2_70"].ToString();
            //            winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
            //            winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
            //            winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
            //            winList.Add(winObj);
            //        }
            //    }

            return winList;
        }

        /// <summary>
        /// 获取系统板块的已选板块
        /// </summary>
        /// <param name="cellNum"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public List<MsWinStyle> GetSysWinShowCell(string cellNum, string Type)
        {
            string sType = (Type != "") ? Type : "0";
            List<MsWinStyle> winList = new List<MsWinStyle>();
            string cmdText = "SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_40,NEWS_B2_60,NEWS_B2_70,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM  NEWS_B2 WHERE NEWS_B2_10 < 0 AND NEWS_B2_40 = '" + cellNum + "' AND NEWS_B2_130 = '-999' AND NEWS_B2_120 = '" + sType + "'";
            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winObj.ShowArea = ireader["NEWS_B2_40"].ToString();
                    winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
                    winObj.SysFlag = ireader["NEWS_B2_70"].ToString();
                    winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
                    winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
                    winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
                    winList.Add(winObj);
                }
            }
            return winList;
        }

        /// <summary>
        /// 获取新用户的默认板块
        /// </summary>
        /// <param name="cellNum"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public List<MsWinStyle> GetDefaultWin(string cellNum, string Type)
        {
            string sType = (Type != "") ? Type : "0";

            List<MsWinStyle> winList = new List<MsWinStyle>();

            if (string.IsNullOrEmpty(cellNum)) return winList;

            string cmdText = " SELECT NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_40,NEWS_B2_60,NEWS_B2_70,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100 FROM  NEWS_B2 WHERE NEWS_B2_40='" + cellNum + "' AND NEWS_B2_120 = '" + sType + "' AND NEWS_B2_130 = '-999' ";

            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winObj.ShowArea = ireader["NEWS_B2_40"].ToString();
                    winObj.TitleStyle = ireader["NEWS_B2_60"].ToString();
                    winObj.SysFlag = ireader["NEWS_B2_70"].ToString();
                    winObj.ShowNum = ireader["NEWS_B2_80"].ToString();
                    winObj.ShowCreateor = ireader["NEWS_B2_90"].ToString();
                    winObj.ShowPubTime = ireader["NEWS_B2_100"].ToString();
                    winList.Add(winObj);
                }
            }
            return winList;
        }

        /// <summary>
        /// 获取未选择的板块(待选板块)
        /// </summary>
        /// <returns></returns>
        public List<MsWinStyle> GetUnSelPlate(string Type)
        {
            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            List<MsWinStyle> winList = new List<MsWinStyle>();

            string sType = (Type != "") ? Type : "0";

            string sSql = "SELECT NEWS_B2_10 , NEWS_B2_20 ,NEWS_B2_30 FROM NEWS_B2 WHERE  NEWS_B2_40 NOT IN (1,2,3) AND NEWS_B2_130 = '" + loginUser.UserId + "' AND NEWS_B2_120 = '" + sType + "'";

            using (IDataReader ireader = DataAccessor.ExecuteReader(sSql))
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winList.Add(winObj);
                }
            }

            ////取系统板块
            //string sysPlate = "SELECT NEWS_B2_10 , NEWS_B2_20 ,NEWS_B2_30 FROM NEWS_B2 WHERE NEWS_B2_10 < 0 AND NEWS_B2_40 NOT IN (1,2,3) AND NEWS_B2_130 = '" + loginUser.UserId + "' AND NEWS_B2_120 = '" + sType + "'";

            //using (IDataReader ireader = DataAccessor.ExecuteReader(sysPlate))
            //{
            //    while (ireader.Read())
            //    {
            //        MsWinStyle winObj = new MsWinStyle();
            //        winObj.PlateId = ireader["NEWS_B2_10"].ToString();
            //        winObj.PlateName = ireader["NEWS_B2_20"].ToString();
            //        winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
            //        winList.Add(winObj);
            //    }
            //}

            ////取当前用户的板块
            //string cmdText = "SELECT NEWS_B2_10 , NEWS_B2_20 ,NEWS_B2_30 FROM NEWS_B2 WHERE NEWS_B2_40 NOT IN (1,2,3) AND NEWS_B2_120 = '" + sType + "'";

            //string plateIds = getUserIds();  // 获取当前用户的板块ids,其中NEWS_A8_70窗口标志为1

            //if (plateIds.Length > 0)
            //{
            //    plateIds = plateIds.Substring(0, plateIds.Length - 1);
            //    cmdText += " AND NEWS_B2_10 IN (" + plateIds + ")";
            //}
            //else
            //{
            //    return winList;
            //}

            //using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
            //{
            //    while (ireader.Read())
            //    {
            //        MsWinStyle winObj = new MsWinStyle();
            //        winObj.PlateId = ireader["NEWS_B2_10"].ToString();
            //        winObj.PlateName = ireader["NEWS_B2_20"].ToString();
            //        winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
            //        winList.Add(winObj);
            //    }
            //}

            return winList;
        }

        /// <summary>
        /// 获取系统板块的待选板块
        /// </summary>
        /// <param name="Type"></param>
        /// <returns></returns>
        public List<MsWinStyle> GetSysUnSelPlate(string Type)
        {
            string sType = (Type != "") ? Type : "0";

            List<MsWinStyle> winList = new List<MsWinStyle>();

            string cmdText = "SELECT NEWS_B2_10 , NEWS_B2_20 ,NEWS_B2_30 FROM NEWS_B2 WHERE NEWS_B2_10 < 0 AND NEWS_B2_40 NOT IN (1,2,3) AND NEWS_B2_130 = '-999' AND NEWS_B2_120 = '" + sType + "'";
            
            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))  //h获取news_b2 表的系统板块
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winList.Add(winObj);
                  //  sysIds += (sysIds == "") ? ireader["NEWS_B2_10"].ToString() : ","+ireader["NEWS_B2_10"].ToString();
                }
            }

            string sysIds = string.Empty;

            string cmdText1 = "SELECT NEWS_B2_10 , NEWS_B2_20 ,NEWS_B2_30 FROM NEWS_B2 WHERE NEWS_B2_10 < 0  AND NEWS_B2_130 = '-999' AND NEWS_B2_120 = '" + sType + "'";
            using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText1))  //h获取news_b2 表的系统板块
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                  //  winList.Add(winObj);
                    sysIds += (sysIds == "") ? ireader["NEWS_B2_10"].ToString() : ","+ireader["NEWS_B2_10"].ToString();
                }
            }


            string sysText =string.Empty;
            if (sysIds != "")   //获取news_b2 表里没有的系统板块
            {
                sysText = "SELECT NEWS_B3_10 , NEWS_B3_20 ,NEWS_B3_30 FROM NEWS_B3 WHERE NEWS_B3_10 NOT IN (" + sysIds + ") AND NEWS_B3_120 = '"+sType+"'";
            }
            else
            {
                sysText = "SELECT NEWS_B3_10 , NEWS_B3_20 ,NEWS_B3_30 FROM NEWS_B3 WHERE  NEWS_B3_120 = '" + sType + "'";
            }

            using (IDataReader ireader = DataAccessor.ExecuteReader(sysText))
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B3_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B3_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B3_30"].ToString();
                    winList.Add(winObj);
                }
            }
            LoginUser login = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            string myselfText = "SELECT NEWS_B2_10 , NEWS_B2_20 ,NEWS_B2_30 FROM NEWS_B2 WHERE NEWS_B2_40 NOT IN (1,2,3) AND NEWS_B2_130 = '" + login.UserId + "' AND NEWS_B2_120 = '" + sType + "' AND NEWS_B2_10 > 0";
            using (IDataReader ireader = DataAccessor.ExecuteReader(myselfText))
            {
                while (ireader.Read())
                {
                    MsWinStyle winObj = new MsWinStyle();
                    winObj.PlateId = ireader["NEWS_B2_10"].ToString();
                    winObj.PlateName = ireader["NEWS_B2_20"].ToString();
                    winObj.PlateLogo = ireader["NEWS_B2_30"].ToString();
                    winList.Add(winObj);
                }
            }

            return winList;
        }
        /// <summary>
        /// 编辑板块对象
        /// </summary>
        /// <param name="winObj"></param>
        /// <returns></returns>
        public List<string> ModifyWinStyleObj(MsWinStyle winObj,string Type,string vUserId)
        {
            string sType = (Type != "")  ? Type : "0";

            LoginUser login = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            List<string> strlist=new List<string>();
            if(winObj.TitleStyle!="")
              winObj.TitleStyle = winObj.TitleStyle.Substring(1,winObj.TitleStyle.Length-1);
            if (winObj == null) return null;

            string cmdLoginUserAttr = "SELECT COUNT(*) FROM NEWS_B2 WHERE NEWS_B2_10 = '" + winObj.PlateId + "' AND NEWS_B2_120 = " + sType + " AND NEWS_B2_130 = '" + login.UserId + "'";
            if (0 == Convert.ToInt32(DataAccessor.ExecuteScalar(cmdLoginUserAttr)))
            {
                MsWinStyle winDefault = GetWinDefault(winObj.PlateId, sType, vUserId);

                string insertText = "INSERT INTO NEWS_B2 VALUES ('" + winDefault.PlateId+ "','"+winDefault.PlateName+"','"+winDefault.PlateLogo+"','"+winDefault.ShowArea+"','"+winDefault.OrderNo+"','"+winDefault.TitleStyle+"','"+winDefault.SysFlag+"','"+winDefault.ShowNum+"','"+winDefault.ShowCreateor+"','"+winDefault.ShowPubTime+"','"+winDefault.OtherSet+"','"+sType+"','"+login.UserId+"')";

                int iexe = DataAccessor.ExecuteNonQuery(insertText);
            }

            string cmdText = "UPDATE NEWS_B2 SET NEWS_B2_20 = '" + winObj.PlateName + "',NEWS_B2_30 = '" + winObj.PlateLogo + "'" +
                              ", NEWS_B2_60 = '" + winObj.TitleStyle + "',NEWS_B2_80 = '" + winObj.ShowNum + "'" +
                              ",NEWS_B2_90 = '" + winObj.ShowCreateor + "', NEWS_B2_100 = '" + winObj.ShowPubTime + "' WHERE NEWS_B2_10 = '" + winObj.PlateId + "' AND NEWS_B2_120 = '" + sType + "' AND NEWS_B2_130 = '" + login.UserId + "'";

            if (0 < DataAccessor.ExecuteNonQuery(cmdText))
            {
                strlist.Add("1");
                strlist.Add("保存成功");
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("系统忙,操作失败,请稍候再试");
            }
            return strlist;  
        }

        /// <summary>
        /// 获取创建信息的用户
        /// </summary>
        /// <param name="newsId"></param>
        /// <returns></returns>
        public string GetUserId(string newsId)
        {
            if (newsId == "") return "";
            string cmdText = "SELECT NEWS_A3_9994 FROM NEWS_A3 WHERE NEWS_A3_10 = '"+newsId+"'";
            string sResult = DataAccessor.ExecuteScalar(cmdText).ToString();
            return sResult;
        }

        /// <summary>
        /// 获取创建信息的时间
        /// </summary>
        /// <param name="newsId"></param>
        /// <returns></returns>
        public string GetPubDate(string newsId)
        {
            if (newsId == "") return "";
            string cmdText = "SELECT NEWS_A3_9995 FROM NEWS_A3 WHERE NEWS_A3_10 = '" + newsId + "'";
            string sResult = DataAccessor.ExecuteScalar(cmdText).ToString();
            return sResult;
        }
        ///// <summary>
        ///// 根据板块类型获取板块ids
        ///// </summary>
        ///// <param name="Type">信息类型</param>
        ///// <returns></returns>
        //public string GetPlateIdByType(string Type)
        //{
        //    string sType = (Type != "") ? Type : "0";
        //    //按类型获取快速查询id
        //    string cmdText = "SELECT NEWS_B2_10 FROM NEWS_B2 WHERE NEWS_B2_120 = '"+sType+"'";
        //    string plateIds = string.Empty;

        //    using (IDataReader ireader = DataAccessor.ExecuteReader(cmdText))
        //    {
        //        while (ireader.Read())
        //        {
        //            plateIds += ireader["NEWS_B2_10"].ToString() + ",";
        //        }
        //    }
        //    //获取板块表中不存在的快速查询id
        //    string AllPlateIds = "SELECT NEWS_B2_10 FROM NEWS_B2 ";
        //    string SumIds = string.Empty;
        //    using (IDataReader ireader = DataAccessor.ExecuteReader(AllPlateIds))
        //    {
        //        while (ireader.Read())
        //        {
        //            SumIds += ireader["NEWS_B2_10"].ToString() + ",";
        //        }
        //    }
        //    if (SumIds != "")
        //    {
        //        SumIds = SumIds.Substring(0, SumIds.Length - 1);
        //        string commonText = "SELECT NEWS_A8_10 FROM NEWS_A8 WHERE NEWS_A8_10 NOT IN (" + SumIds + ") AND NEWS_A8_70 = '0'";
        //        using (IDataReader ireader = DataAccessor.ExecuteReader(commonText))
        //        {
        //            while (ireader.Read())
        //            {
        //                plateIds += ireader["NEWS_A8_10"].ToString() + ",";
        //            }
        //        }
        //    }


        //    if (plateIds != "")
        //        plateIds = plateIds.Substring(0, plateIds.Length - 1);

        //    return plateIds;
        //}

        #endregion

        #region 私有方法

        /// <summary>
        /// 获取当前用户的板块ids
        /// </summary>
        /// <returns></returns>
        //private static string getUserIds()
        //{
        //    LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
        //    List<MsQueryClause> mqc = new List<MsQueryClause>();
        //    string plateIds = string.Empty;
        //    string clauseIds = " SELECT NEWS_A8_10 FROM NEWS_A8 WHERE NEWS_A8_20='" + loginUser.UserId + "' AND NEWS_A8_70='1'";
        //    using (IDataReader clauseRead = DataAccessor.ExecuteReader(clauseIds))
        //    {
        //        while (clauseRead.Read())
        //        {
        //            plateIds += clauseRead["NEWS_A8_10"].ToString() + ",";
        //        }
        //    }
        //    return plateIds;
        //}

        // 新增
        private static List<string> doSave(MsWinStyle winObj, MsQueryClause queryClause,string Type)
        {
            string sType = (Type != "") ? Type : "0";

            List<string> strlist = new List<string>();
            string[] pubMsg = SessionExt.GetSysFieldSQL("NEWS_A8");
            LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            string strMaxId = DataInterface.GetMaxId("NEWS_A8", "NEWS_A8_10").ToString();
            //快速查询条件表
            string ClauseText = "INSERT INTO NEWS_A8 (NEWS_A8_10,NEWS_A8_20,NEWS_A8_30,NEWS_A8_40,NEWS_A8_50,NEWS_A8_60,NEWS_A8_70," + pubMsg[0] + ") " +
                            " VALUES ('" + strMaxId + "','" + loginUser.UserId + "','" + sType + "','" + winObj.PlateName + "','" + queryClause.ClauseContent + "','0','1'," + pubMsg[1] + ")";
            if (0 < DataAccessor.ExecuteNonQuery(ClauseText))
            {
                strlist.Add("1");
                strlist.Add("保存成功");
                strlist.Add(strMaxId);
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("保存失败");
                strlist.Add("");
            }
            if (winObj.TitleStyle != "")
                winObj.TitleStyle = winObj.TitleStyle.Substring(1, winObj.TitleStyle.Length - 1);

            
            //版块表
            string WinText = "INSERT INTO NEWS_B2 (NEWS_B2_10,NEWS_B2_20,NEWS_B2_30,NEWS_B2_40,NEWS_B2_50,NEWS_B2_60,NEWS_B2_70,NEWS_B2_80,NEWS_B2_90,NEWS_B2_100,NEWS_B2_110,NEWS_B2_120,NEWS_B2_130)";
            WinText += "VALUES ('" + strMaxId + "','" + winObj.PlateName + "','" + winObj.PlateLogo + "','0','" + winObj.OrderNo + "','" + winObj.TitleStyle + "','0','" + winObj.ShowNum + "','" + winObj.ShowCreateor + "','" + winObj.ShowPubTime + "','" + winObj.OtherSet + "','" + sType + "','" + loginUser.UserId+ "')";            
            if (0 < DataAccessor.ExecuteNonQuery(WinText))
            {
                strlist.Add("1");
                strlist.Add("保存成功");
                strlist.Add(strMaxId);
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("保存失败");
                strlist.Add("");
            }
            return strlist;
        }

        //编辑
        private static List<string> doEdit(MsWinStyle winObj, MsQueryClause queryClause)
        {
            List<string> strlist = new List<string>();
            string ClauseText = "UPDATE NEWS_A8 SET NEWS_A8_50='" + queryClause.ClauseContent + "' WHERE NEWS_A8_10='"+queryClause.ClauseId+"'";
            if (0 < DataAccessor.ExecuteNonQuery(ClauseText))
            {
                strlist.Add("1");
                strlist.Add("保存成功");
                strlist.Add(queryClause.ClauseId);
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("保存失败");
                strlist.Add("");
            }
            if (winObj.TitleStyle != "")
                winObj.TitleStyle = winObj.TitleStyle.Substring(1, winObj.TitleStyle.Length - 1);
            string WinText = "UPDATE NEWS_B2 SET NEWS_B2_20='" + winObj.PlateName + "',NEWS_B2_30='" + winObj.PlateLogo + "',NEWS_B2_60='" + winObj.TitleStyle + "',";
            WinText += " NEWS_B2_80='" + winObj.ShowNum + "',NEWS_B2_90='" + winObj.ShowCreateor + "',NEWS_B2_100='" + winObj.ShowPubTime + "' WHERE NEWS_B2_10='"+winObj.PlateId+"'";                     
            if (0 < DataAccessor.ExecuteNonQuery(WinText))
            {
                strlist.Add("1");
                strlist.Add("保存成功");
                strlist.Add(winObj.PlateId);
            }
            else
            {
                strlist.Add("-1");
                strlist.Add("保存失败");
                strlist.Add("");
            }
            return strlist;
        }


        #endregion



    }
}
